#ifndef DEVICE_H_INCLUDED
#define DEVICE_H_INCLUDED

#include <irrlicht.h>
#include <irrKlang.h>
#include <lua.hpp>
#include "helper.h"
#include "cTriggers.h"

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
using namespace irrklang;

struct SDevice {
	IrrlichtDevice* Device;
	IVideoDriver* Driver;
	IGUIEnvironment* GUI;

	ISoundEngine* SoundEngine;

	array<ISceneNode*> Nodes;
	array<IGUIElement*> GUIElements;
	array<ISceneManager*> Scenes;
	array<IMetaTriangleSelector*> MetaSelectors;
	array<stringc> KeyActions;
	array<bool> KeyState;
	array<stringc> EngineActions;
	array<stringc> EngineActionTables;
	cTriggerManager Tmgr;
	IMeshSceneNode* Dummy;
	IGUIStaticText* Tooltip;

	int ActiveScene = 0;

	uint UseKey = KEY_KEY_E;

	lua_State* L;

	void Init(){
		Driver = Device->getVideoDriver();
		GUI = Device->getGUIEnvironment();

		Driver->setTextureCreationFlag(ETCF_ALWAYS_32_BIT, true);

		Scenes.push_back(Device->getSceneManager());

		MetaSelectors.push_back(Scene()->createMetaTriangleSelector());

		Nodes.push_back(Scene()->getRootSceneNode());
		array<uint> SceneNode;

		GUIElements.push_back(GUI->getRootGUIElement());
		for (int i=0; i<=KEY_KEY_CODES_COUNT; i++) {
			KeyActions.push_back("");
			KeyState.push_back(false);
		}

		EngineActions.push_back(""); //EngineActions[EVERY_FRAME] = "";

		SoundEngine = createIrrKlangDevice();
		if (!SoundEngine) printf("Failed to start sound engine!\n");
	}

	ISceneManager* Scene() {
		return Scenes[ActiveScene];
	}

}P;

#endif // DEVICE_H_INCLUDED
